<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/css/index.css">
    <link rel="stylesheet" href="/static/css/common.css">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/static/css/spec.css">
</head>
<body>
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <input type="hidden" name="id" value="{$find.id}">
    <input type="hidden" name="pid" value="{$find.pid}">
    <div class="layui-form-item">
        <label class="layui-form-label">选择商品</label>
        <div class="layui-input-inline" style="width: 300px;">
            <input type="text" value="{$find.name}" ts-selected="{$find.pid}" id="demo" lay-verify="required" placeholder="选择商品" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">评价图片</label>
        <div class="layui-input-block">
            <p class="up-p" style="line-height: 38px;"><span class="up-span">最多可以上传5张图片</span></p>
            <div class="z_photo upimg-div clear">
                {volist name='img' id='vo'}
                <section class="up-section fl">
                    <span class="up-span"></span>
                    <img class="close-upimg" src="/static/img/a7.png">
                    <img class="up-img" src="/uploads/{$vo.img}">
                    <p class="img-name-p">{$vo.img}</p>
                    <input id="taglocation" name="taglocation" value="" type="hidden">
                    <input id="tags" name="tags" value="" type="hidden">
                    <input type="text" style="display:none;" name="img" value="{$vo.img}">
                </section>
                {/volist}
                {if condition="count($img) > 4"}
                <section class="z_file fl" style="display: none;">
                    <img src="/static/img/a11.png" class="add-img">
                    <input style="cursor: pointer;" type="file" name="file" lay-verify="img" id="file" class="file" value="" accept="image/jpg,image/jpeg,image/png,image/bmp" multiple />
                </section>
                {else /}
                <section class="z_file fl">
                    <img src="/static/img/a11.png" class="add-img">
                    <input style="cursor: pointer;" type="file" name="file" lay-verify="img" id="file" class="file" value="" accept="image/jpg,image/jpeg,image/png,image/bmp" multiple />
                </section>
                {/if}
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">评论详情</label>
        <div class="layui-input-block" style="width: 500px;">
            <textarea name="content" placeholder="评论详情" class="layui-textarea">{$find.content}</textarea>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="提交">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="修改">
    </div>
    <script type="text/html" id="time">
        {{ formatDateTime(d.time) }}
    </script>
</div>
<script src="/static/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/static/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="/static/js/imgUp.js"></script>
<script type="text/javascript" src="/static/js/imgPlugin.js"></script>
<script>
    //产品图片多图上传
    $("#file").takungaeImgup({
        formData: {
            "name": "img"
        },
        url: "{:url('Product/shopUpload')}",
        success: function(data) {},
        error: function(err) {
            alert(err);
        }
    });

    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'laydate', 'form', 'tableSelect'], function(){
        var $ = layui.$,
                form = layui.form,
                laydate = layui.laydate,
                tableSelect = layui.tableSelect;

        tableSelect.render({
            elem: '#demo',	//定义输入框input对象
            checkedKey: 'id', //表格的唯一建值，非常重要，影响到选中状态 必填
            searchKey: 'name',	//搜索输入框的name值 默认keyword
            searchPlaceholder: '搜索商品名称',	//搜索输入框的提示文字 默认关键词搜索
            table: {	//定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                url: "{:url('Product/product')}",
                method: 'post',
                cols: [[
                    {type: 'radio'},
                    {field: 'name', title: '商品名称', width: 400},
                    {field: 'stock', title: '库存', width: 100},
                    {field: 'volume', title: '销量', width: 100},
                    {field: 'time', title: '添加时间', width: 200, templet: "#time"}
                ]]
            },
            done: function (elem, data) {
                //选择完后的回调，包含2个返回值 elem:返回之前input对象；data:表格返回的选中的数据 []
                //拿到data[]后 就按照业务需求做想做的事情啦~比如加个隐藏域放ID...
                var field = data.data;
                $("input[name=pid]").val(field[0].id);
                $("#demo").val(field[0].name);
            }
        });

        //添加
        form.on('submit(layuiadmin-app-form-submit)', function(data){
            var field = data.field;
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            var img = [];
            $.each($('input[name=img]'), function () {
                img.push($(this).val());
            });
            field.img = img;
            $.post("{:url('Product/evaluate_add')}", {field:field}, function(e){
                if (e == 1){
                    layer.msg('添加成功', {icon: 1});
                    setTimeout(function () {
                        parent.layui.table.reload('demo'); //重载表格
                        parent.layer.close(index); //再执行关闭
                    }, 500)
                }else{
                    layer.msg('添加失败', {icon: 2});
                }
            })
        });

        //修改
        form.on('submit(layuiadmin-app-form-edit)', function(data){
            var field = data.field;
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            var img = [];
            $.each($('input[name=img]'), function () {
                img.push($(this).val());
            });
            field.img = img;
            $.post("{:url('Product/evaluate_edit')}", {field:field}, function(e){
                if (e == 1){
                    layer.msg('修改成功', {icon: 1});
                    setTimeout(function () {
                        parent.layui.table.reload('demo'); //重载表格
                        parent.layer.close(index); //再执行关闭
                    }, 500)
                }else{
                    layer.msg('修改失败', {icon: 2});
                }
            })
        });
    });

    //php时间戳用js转换为yyyy-mm-dd
    function formatDateTime(timeStamp) {
        var date = new Date();
        date.setTime(timeStamp * 1000);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        var h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        var minute = date.getMinutes();
        var second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    }
</script>
</body>
</html>